import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { Exclude } from 'class-transformer';
import { Comment } from '../../comments/entities/comment.entity';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'varchar', length: 128, comment: '用户名', unique: true })
  username: string;

  @Exclude()
  @Column({ type: 'varchar', length: 128, comment: '密码' })
  password: string;

  @Column({ type: 'varchar', length: 255, comment: '用户头像', nullable: true })
  avatarUrl: string;

  @Column({
    type: 'varchar',
    length: 50,
    comment: '邮箱',
    nullable: true,
    unique: true,
  })
  email: string;

  @Column({
    type: 'varchar',
    length: 20,
    comment: '手机号',
    nullable: true,
    unique: true,
  })
  phone: string;

  @Column({
    type: 'varchar',
    length: 10,
    comment: '权限: admin user',
    default: 'user',
  })
  role: string;

  @Column({
    type: 'varchar',
    length: 255,
    comment: '友链',
    nullable: true,
    default: '',
  })
  websiteUrl: string;

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;

  @Column({ nullable: true })
  deleteTime: Date;

  @Column({ comment: '是否已删除', default: false })
  isDeleted: boolean = false;

  @OneToMany(() => Comment, (comment) => comment.member)
  comments: Comment[];
}
